const _ = require('underscore')

Component({
  data: {
    value: '',
    list: []
  },

  methods: {
    _search() {
      const db = wx.cloud.database()
      db
        .collection('minipet')
        .where({
          message: db.RegExp({
            regexp: '^' + this.data.value
          })
        })
        .get({
          success: result => {
            this.setData({
              list: result.data
            })
          }
        })
    },

    onSearch() {
      this._search()
    },

    onChange: _.debounce(function(e){
      this.setData({
        value: e.detail
      })
      this._search()
    }, 300),

    onCancel() {
      
    }
  }
})